﻿<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/css" href="Style.css" ?>
<xsl:stylesheet version="1.0" 
				xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
				xmlns:msxml="urn:schemas-microsoft-com:xslt"
				xmlns:mv="urn:my-scripts">
	<xsl:output encoding="iso-8859-1" indent="yes" method="html" version="4.0" />
  <xsl:param name="filter" />
  <xsl:template match="/">
	  <xsl:choose>
		  <xsl:when test="$filter = 'Attribute Flow Precedence'">
			  <xsl:call-template name="AttributeFlowPrecedence" />
		  </xsl:when>
		  <xsl:otherwise>
			  <xsl:call-template name="FIMObjects" />
		  </xsl:otherwise>
	  </xsl:choose>
  </xsl:template>
   <!--======================================================================================-->
   <!-- Template to display the general data                                                 -->
   <!--======================================================================================-->
	<xsl:template name="FIMObjects">
		<table id="tdata" style="border: 1px ActiveBorder groove">
			<xsl:variable name="curmode" select="Results/@Objects" />
			<tr>
				<td style="font-family: Tahoma; font-size:11px;padding-top: 5px;padding-bottom: 5px;padding-left: 10px;padding-right: 10px;font-weight: bold;background: rgb(234,242,255);border-bottom: 1px solid rgb(120,172,255);">
					<xsl:choose>
						<xsl:when test="$filter = 'SynchronizationRule'">
							<xsl:text>Synchronization Rules</xsl:text>
						</xsl:when>
						<xsl:when test="$filter = 'ManagementPolicyRule'">
							<xsl:text>Management Policy Rules</xsl:text>
						</xsl:when>
						<xsl:when test="$filter = 'WorkflowDefinition'">
							<xsl:text>Workflows</xsl:text>
						</xsl:when>
						<xsl:when test="$filter = 'ma-data'">
							<xsl:text>Management Agents</xsl:text>
						</xsl:when>
						<xsl:when test="$filter = 'Set'">
							<xsl:text>Sets</xsl:text>
						</xsl:when>
						<xsl:otherwise>
							<xsl:text>Object List</xsl:text>
						</xsl:otherwise>
					</xsl:choose>
				</td>
			</tr>
			<tr>
				<td>
					<ol style="font-family: Tahoma; font-size:11px; line-height: 30px;">
						<xsl:for-each select="//ResourceManagementObject[ObjectType=$filter]">
							<xsl:sort select="ResourceManagementAttribute[AttributeName='DisplayName']/Value" />
							<li>
								<xsl:attribute name="style">
									padding-left:10px;
									padding-right:10px;
									padding-top:4px;
									padding-bottom:4px;
									<xsl:if test="(position() mod 2 = 0)">
										background-color:#F5F5DC;
									</xsl:if>
								</xsl:attribute>

								<a>
									<xsl:attribute name="style">
										color:black
									</xsl:attribute>
									<xsl:attribute name="href">
										<xsl:text>about:</xsl:text>
										<xsl:value-of select="$filter" />
										<xsl:text>:</xsl:text>
										<xsl:variable name="objectid" select="ObjectIdentifier" />
										<xsl:value-of select="substring-after($objectid, 'urn:uuid:')" />
									</xsl:attribute>
									<xsl:value-of select="ResourceManagementAttributes/ResourceManagementAttribute[AttributeName='DisplayName']/Value" />
								</a>
							</li>
						</xsl:for-each>
					</ol>
				</td>
			</tr>
		</table>
	</xsl:template>
	<!--======================================================================================-->
	<!-- Template to display the general data                                                 -->
	<!--======================================================================================-->
	<xsl:template name="AttributeFlowPrecedence">
		<xsl:variable name="IafNodes" select="mv:parse(//ExportObject/ResourceManagementObject[ObjectType='mv-data']/ResourceManagementAttributes/ResourceManagementAttribute[AttributeName='SyncConfig-import-attribute-flow']/Value)" />

		<table id="tdata" style="border: 1px ActiveBorder groove">
			<tr>
				<td style="font-family: Tahoma; font-size:11px;padding-top: 5px;padding-bottom: 5px;padding-left: 10px;padding-right: 10px;font-weight: bold;background: rgb(234,242,255);border-bottom: 1px solid rgb(120,172,255);">
					<xsl:text>Attribute Flow Precedence</xsl:text>
				</td>
			</tr>
			<tr>
				<td>
					<ol style="font-family: Tahoma; font-size:11px; line-height: 30px;">
						<xsl:for-each select="$IafNodes/import-flow-set">
							<xsl:sort select="@mv-object-type" />
							<li>
								<xsl:attribute name="style">
									padding-left:10px;
									padding-right:10px;
									padding-top:4px;
									padding-bottom:4px;
									<xsl:if test="(position() mod 2 = 0)">
										background-color:#F5F5DC;
									</xsl:if>
								</xsl:attribute>
								<a>
									<xsl:attribute name="style">
										color:black
									</xsl:attribute>
									<xsl:attribute name="href">
										<xsl:text>about:AttributeFlowPrecedence:</xsl:text>
										<xsl:value-of select="@mv-object-type" />
									</xsl:attribute>
									<xsl:value-of select="@mv-object-type" />
								</a>
							</li>
						</xsl:for-each>
					</ol>
				</td>
			</tr>
		</table>
	</xsl:template>
	<!--===================================================================================================================================-->
	<!-- Script to convert XML Text into XML Node List                                                                                     -->
	<!--===================================================================================================================================-->
	<msxml:script language="CSharp" implements-prefix="mv">
		<msxml:using namespace="System.IO" />
		public XPathNodeIterator parse(string data)
		{
		String xmlString = "&lt;root&gt;" + data + "&lt;/root&gt;";
		StringReader stringReader = new StringReader(xmlString);

		XPathDocument xPathDocument = new XPathDocument(stringReader);
		XPathNavigator xPathNavigator = xPathDocument.CreateNavigator();

		return xPathNavigator.Select("root");
		}
	</msxml:script>
</xsl:stylesheet>
